//
//  SecondHandCarViewController.m
//  OneCreditTreasure
//
//  Created by iOS Grouper on 16/8/29.
//
//

#import "SecondHandCarViewController.h"
#import "YHYcommenTableViewCell.h"
#import "nextsecondHandViewController.h"
#import "ActionSheetPicker.h"
#import "AbstractActionSheetPicker+Interface.h"//这个是定义取消和确定按钮
//#import "XKPEActionPickersDelegate.h"
//#import "XKPEWeightAndHightActionPickerDelegate.h"

@interface SecondHandCarViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate>{
    UITableView *myTableView;
    NSMutableArray *titleArray;
    UIButton *nextButton;
}
@property (nonatomic , strong) NSDate         *selectedDate;

@end

@implementation SecondHandCarViewController
- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"二手车贷款";
    titleArray = [NSMutableArray arrayWithObjects:@"品牌",@"车型",@"上牌时间",@"行驶里程",@"车价",@"车行名称",@"车行电话",nil];
    self.selectedDate = [NSDate date];//日期时用

    [self creatView];
    
}
- (void)creatView{
    myTableView = [UITableView new];
    myTableView.backgroundColor = LV;
    [self.view addSubview:myTableView];
    [myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view);
        make.left.mas_equalTo(self.view);
        make.width.mas_equalTo(kScreenW);
        make.height.mas_equalTo(kScreenH);
        
    }];
    myTableView.delegate = self;
    myTableView.dataSource = self;
    [myTableView registerClass:[YHYcommenTableViewCell class] forCellReuseIdentifier:@"YHYcommenTableViewCell"];
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [myTableView reloadData];
    
    
    
    nextButton = [UIButton new];
    [self.view addSubview:nextButton];
    [nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view);
        make.height.mas_equalTo(50 * AUTO_HEIGHT);
        make.left.mas_equalTo(0);
        make.centerXWithinMargins.mas_equalTo(self.view);
        
    }];
    nextButton.backgroundColor = [UIColor whiteColor];
    nextButton.titleLabel.font = [UIFont fontWithName:ZIXING size:14 ];
    [nextButton setTitleColor:HS forState:UIControlStateNormal];
    [nextButton setTitle:@"下一步" forState:UIControlStateNormal];
    [nextButton addTarget:self action:@selector(nextButton:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIView *line = [UIView new];
    [nextButton addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(nextButton.mas_top);
        make.height.mas_equalTo(0.4);
        make.width.mas_equalTo(kScreenW);
        
        
    }];
    line.backgroundColor = HS;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return titleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YHYcommenTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHYcommenTableViewCell"];
    cell.leftTitleL.text = titleArray[indexPath.row];
    cell.textL.text = @"奥迪";
    if (indexPath.row < 5) {
        cell.type = TYPEB;
    }
    if (indexPath.row == 3) {
        cell.rightTextL.text = @"万公里";
    }
    if (indexPath.row == 4) {
        cell.rightTextL.text = @"万元";
    }
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 2) {
        [self getPick];
    }
}

//选择时间
- (void)dateWasSelected:(NSDate *)selectedDate element:(id)element {
    NSLog(@"选择的时间%@",selectedDate);
}



- (void)getPick{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *minimumDateComponents = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay  fromDate:[NSDate date]];
    [minimumDateComponents setYear:1950];//最小日期
    NSDate *minDate = [calendar dateFromComponents:minimumDateComponents];
    NSDate *maxDate = [NSDate date];//最大日期，今天
    ActionSheetDatePicker *actionSheetPicker = [[ActionSheetDatePicker alloc] initWithTitle:@"请选择日期" datePickerMode:UIDatePickerModeDate selectedDate:self.selectedDate                                                              target:self action:@selector(dateWasSelected:element:) origin:self.view];
      [actionSheetPicker customizeInterface];
    [actionSheetPicker setMinimumDate:minDate];
    [actionSheetPicker setMaximumDate:maxDate];
    [actionSheetPicker showActionSheetPicker];
}
//下一步
- (void)nextButton:(UIButton *)btu{
    nextsecondHandViewController *next = [nextsecondHandViewController new];
    [self.navigationController pushViewController:next animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
